﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.UI
{
    /// <summary>
    /// Interaction logic for ServerAddressConfigWindow.xaml
    /// </summary>
    public partial class ServerAddressConfigWindow : Window
    {
        public string ServerAddress { get; set; }

        public ServerAddressConfigWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.tbAddress.Text = LocalConfigService.GetValue("ServerAddress", "http://www.76df.com:8080/proxydelivery");
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            string newAddress = this.tbAddress.Text.Trim();

            if (string.IsNullOrEmpty(newAddress))
            {
                MessageBox.Show("服务器地址不能为空");
                return;
            }
            this.ServerAddress = this.tbAddress.Text.Trim();
            LocalConfigService.UpdateValue("ServerAddress", this.ServerAddress);
            ServiceContainer.ServerAddress = this.ServerAddress;
            this.DialogResult = true;
        }
    }
}
